<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="12">
            <a-form-model-item label="开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="beginDate">
              <!-- <j-date :disabled=formDisabled placeholder="请选择开始时间" v-model="model.beginDate"  style="width: 100%" /> -->
              <a-date-picker :disabled="formDisabled" placeholder="请选择开始日期" valueFormat="YYYY-MM-DD" @change="handleChange" v-model="model.beginDate" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="结束日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="endDate">
              <!-- <j-date :disabled=formDisabled placeholder="请选择结束日期" v-model="model.endDate"  style="width: 100%" /> -->
              <a-date-picker
                :disabled="formDisabled"
                :disabled-date="disabledDate"
                :default-picker-value="this.model.beginDate"
                placeholder="请选择结束日期"
                valueFormat="YYYY-MM-DD"
                v-model="model.endDate"
                style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12">
            <a-form-model-item label="教育单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="institution">
              <a-input :disabled=formDisabled v-model="model.institution" placeholder="请输入教育单位"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="12">
            <a-form-model-item label="学校名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="graduatedFrom">
              <a-input :disabled=formDisabled v-model="model.graduatedFrom" placeholder="请输入学校名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="专业" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="major">
              <a-input :disabled=formDisabled v-model="model.major" placeholder="请输入专业"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="获奖情况" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="prizeRecord">
              <a-input :disabled=formDisabled v-model="model.prizeRecord" placeholder="请输入获奖情况"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="附件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="attachment">
              <j-upload :disabled=formDisabled  v-model="model.attachment"></j-upload>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import moment from 'moment';

export default {
  name: 'ErpEmployeeEducationForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {},
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 },
      },
      confirmLoading: false,
      validatorRules: {
        // institution: [
        //   { required: true, message: '请输入教育培训所在机构!' },
        //   { validator: (rule, value, callback) => validateBlankValue('erp_employee_education', 'institution', value, this.model.id, callback) },
        // ],
        major:[{ required: true, message: '请输入专业!' },],
        graduatedFrom: [
          { required: true, message: '请输入学校名称!' },
          // { validator: (rule, value, callback) => validateBlankValue('erp_employee_education', 'graduatedFrom', value, this.model.id, callback) },
        ],
      },
      url: {
        add: '/api/erp/files/employee/erpEmployeeEducation/add',
        edit: '/api/erp/files/employee/erpEmployeeEducation/edit',
        queryById: '/api/erp/files/employee/erpEmployeeEducation/queryById'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    moment,
    handleChange(value) {
      if (this.model.endDate) {
        if ((this.model.endDate).diff((this.model.beginDate), 'days') < 0) {
          this.model.endDate = this.model.beginDate
        }
      }
    },
    disabledDate(current) {
      return current < moment(this.model.beginDate).subtract('day')
    },
    add() {
      this.edit(this.modelDefault);
    },
    edit(record) {
      this.$refs.form.clearValidate()
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          // that.confirmLoading = true;
          // let httpurl = '';
          // let method = '';
          // if (!this.model.id) {
          //   httpurl += this.url.add;
          //   method = 'post';
          // } else {
          //   httpurl += this.url.edit;
          //   method = 'put';
          // }
          // httpAction(httpurl, this.model, method).then((res) => {
          //   if (res.success) {
          //     that.$message.success(res.message);
          //     that.$emit('ok');
          //   } else {
          //     that.$message.warning(res.message);
          //   }
          // }).finally(() => {
          //   that.confirmLoading = false;
          // })
          that.$emit('ok',that.model);
        }

      })
    },
  }
}
</script>
